package com.qf.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qf.annotation.RequiresPermissionsDesc;
import com.qf.pojo.DtsOrder;
import com.qf.service.DtsOrderService;
import com.qf.util.ResponseUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * @author lixu
 */
@RestController
@RequestMapping("/admin/order")
@CrossOrigin
public class OrderController {

    @Autowired
    private DtsOrderService dtsOrderService;


    /**
     * 订单列表 ctrl + alt +o
     * - 接口地址 : http://localhost:8083/admin/order/list?page=1&limit=20&sort=add_time&order=desc
     *
     * - 下行数据 :
     */
    @RequiresPermissionsDesc(menu = {"商场管理","订单管理"},button = "查询")
    @RequiresPermissions(value = "admin:order:list")
    @GetMapping("/list")
    public Object list(Integer userId,
                       String orderSn,
                       Integer orderStatus,
                       String sort,
                       String order,
                       @RequestParam(defaultValue = "1") Integer page,
                       @RequestParam(defaultValue = "20") Integer limit
    ){
        IPage<DtsOrder> iPage = dtsOrderService.findListByQuery(userId,orderSn,orderStatus,sort,order,page,limit);
        Map data = new HashMap<>();
        data.put("total",iPage.getTotal());
        data.put("items",iPage.getRecords());
        return ResponseUtil.ok(data);
    }


    @RequiresPermissionsDesc(menu = {"商场管理","订单管理"},button = "详情")
    @RequiresPermissions(value = "admin:order:detail")
    @GetMapping("/detail")
    public Object list(@RequestBody DtsOrder dtsOrder){
        //TODO dtsOrder = dtsOrderService.detail(dtsOrder);
        return ResponseUtil.ok(dtsOrder);
    }
}
